#include <bits/stdc++.h>
using namespace std;
int n, m, T;
int a[100005], c[100005];
int b[15][15];

int main()
{
	freopen("arena.in", "r", stdin);
	freopen("arena.out", "w", stdout);
	
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= m; i++)
		cin >> c[i];
	int x = 1, sum = 2;
	while (sum < n){
		sum *= 2;
		x++;
	}
	for (int j = 1; j <= x; j++)
		for (int k = 1; k <= pow(2, x - j); k++){
			char c;
			cin >> c;
			b[j][k] = c - '0';
		}
	cin >> T;
	for (int i = 1; i <= T; i++){
		int x[4];
		cin >> x[0] >> x[1] >> x[2] >> x[3];
		for (int j = 1; j <= n; j++)
			a[j] = a[j] ^ x[j % 4];
		srand(time(0));
		cout << rand() % 100 << endl;
	}
	
	fclose(stdin);
	fclose(stdout);
	
	return 0;
}
